
<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" charset="utf-8">
			// 创建一个Socket实例
			var socket = new WebSocket('ws://127.0.0.1:8080/ws/long');
			
			// 打开Socket 
			socket.onopen = function(event) { 			
			  // 发送一个初始化消息
			  socket.send('I am the client and I\'m listening!'); 
			}
			
			  // 监听消息
			  socket.onmessage = function(event) { 
			    console.log('Client received a message',event); 
			  }; 
			
			  // 监听Socket的关闭
			  socket.onclose = function(event) { 
			    console.log('Client notified socket has closed',event); 
			  }; 
        
        function send()
  			{
          var date = new Date();
  				socket.send(date.toLocaleString());
  			}
			
			  // 关闭Socket.... 
			  //socket.close() 
        

        </script>
    </head>
    <body>
       <p>see your browser's console</p>
        <button onclick="send()">Send</button>
    </body>
</html>